functor BJKLrValsFun(structure Token : TOKEN)
 : sig structure ParserData : PARSER_DATA
       structure Tokens : BJK_TOKENS
   end
 = 
struct
structure ParserData=
struct
structure Header = 
struct
(* BJK Core language withe resets ML-Yacc parser *)

end
structure LrTable = Token.LrTable
structure Token = Token
local open LrTable in 
val table=let val actionRows =
"\
\\001\000\001\000\000\000\000\000\
\\001\000\001\000\041\000\002\000\009\000\000\000\
\\001\000\001\000\042\000\002\000\042\000\006\000\042\000\000\000\
\\001\000\001\000\043\000\002\000\043\000\005\000\023\000\006\000\043\000\
\\007\000\022\000\000\000\
\\001\000\001\000\044\000\002\000\044\000\006\000\044\000\000\000\
\\001\000\001\000\045\000\002\000\045\000\006\000\045\000\000\000\
\\001\000\001\000\046\000\002\000\046\000\006\000\046\000\000\000\
\\001\000\001\000\047\000\002\000\047\000\006\000\047\000\000\000\
\\001\000\001\000\048\000\002\000\048\000\005\000\048\000\006\000\048\000\
\\007\000\048\000\018\000\048\000\000\000\
\\001\000\001\000\049\000\002\000\049\000\005\000\049\000\006\000\049\000\
\\007\000\022\000\018\000\049\000\000\000\
\\001\000\001\000\050\000\002\000\050\000\005\000\050\000\006\000\050\000\
\\007\000\050\000\018\000\050\000\000\000\
\\001\000\001\000\051\000\002\000\051\000\005\000\051\000\006\000\051\000\
\\007\000\051\000\018\000\051\000\000\000\
\\001\000\001\000\052\000\002\000\052\000\005\000\052\000\006\000\052\000\
\\007\000\052\000\018\000\052\000\000\000\
\\001\000\002\000\009\000\006\000\025\000\000\000\
\\001\000\002\000\009\000\006\000\026\000\000\000\
\\001\000\002\000\009\000\006\000\033\000\000\000\
\\001\000\002\000\009\000\006\000\038\000\000\000\
\\001\000\002\000\009\000\006\000\039\000\000\000\
\\001\000\003\000\011\000\000\000\
\\001\000\003\000\012\000\000\000\
\\001\000\003\000\021\000\000\000\
\\001\000\003\000\034\000\000\000\
\\001\000\003\000\035\000\000\000\
\\001\000\005\000\023\000\007\000\022\000\018\000\030\000\000\000\
\\001\000\008\000\018\000\014\000\017\000\017\000\016\000\000\000\
\\001\000\009\000\008\000\010\000\007\000\012\000\006\000\014\000\005\000\
\\016\000\004\000\000\000\
\\001\000\011\000\032\000\000\000\
\\001\000\013\000\031\000\000\000\
\\001\000\014\000\013\000\000\000\
\\001\000\015\000\010\000\000\000\
\"
val actionRowNumbers =
"\025\000\001\000\002\000\029\000\
\\018\000\019\000\028\000\025\000\
\\024\000\025\000\025\000\020\000\
\\004\000\003\000\024\000\008\000\
\\011\000\013\000\014\000\025\000\
\\024\000\024\000\023\000\027\000\
\\026\000\015\000\010\000\009\000\
\\012\000\021\000\022\000\005\000\
\\025\000\025\000\016\000\017\000\
\\007\000\006\000\000\000"
val gotoT =
"\
\\002\000\001\000\003\000\038\000\000\000\
\\000\000\
\\000\000\
\\000\000\
\\000\000\
\\000\000\
\\000\000\
\\002\000\012\000\000\000\
\\001\000\013\000\000\000\
\\002\000\017\000\000\000\
\\002\000\018\000\000\000\
\\000\000\
\\000\000\
\\000\000\
\\001\000\022\000\000\000\
\\000\000\
\\000\000\
\\000\000\
\\000\000\
\\002\000\025\000\000\000\
\\001\000\026\000\000\000\
\\001\000\027\000\000\000\
\\000\000\
\\000\000\
\\000\000\
\\000\000\
\\000\000\
\\000\000\
\\000\000\
\\000\000\
\\000\000\
\\000\000\
\\002\000\034\000\000\000\
\\002\000\035\000\000\000\
\\000\000\
\\000\000\
\\000\000\
\\000\000\
\\000\000\
\"
val numstates = 39
val numrules = 12
val s = ref "" and index = ref 0
val string_to_int = fn () => 
let val i = !index
in index := i+2; Char.ord(String.sub(!s,i)) + Char.ord(String.sub(!s,i+1)) * 256
end
val string_to_list = fn s' =>
    let val len = String.size s'
        fun f () =
           if !index < len then string_to_int() :: f()
           else nil
   in index := 0; s := s'; f ()
   end
val string_to_pairlist = fn (conv_key,conv_entry) =>
     let fun f () =
         case string_to_int()
         of 0 => EMPTY
          | n => PAIR(conv_key (n-1),conv_entry (string_to_int()),f())
     in f
     end
val string_to_pairlist_default = fn (conv_key,conv_entry) =>
    let val conv_row = string_to_pairlist(conv_key,conv_entry)
    in fn () =>
       let val default = conv_entry(string_to_int())
           val row = conv_row()
       in (row,default)
       end
   end
val string_to_table = fn (convert_row,s') =>
    let val len = String.size s'
        fun f ()=
           if !index < len then convert_row() :: f()
           else nil
     in (s := s'; index := 0; f ())
     end
local
  val memo = Array.array(numstates+numrules,ERROR)
  val _ =let fun g i=(Array.update(memo,i,REDUCE(i-numstates)); g(i+1))
       fun f i =
            if i=numstates then g i
            else (Array.update(memo,i,SHIFT (STATE i)); f (i+1))
          in f 0 handle Subscript => ()
          end
in
val entry_to_action = fn 0 => ACCEPT | 1 => ERROR | j => Array.sub(memo,(j-2))
end
val gotoT=Array.fromList(string_to_table(string_to_pairlist(NT,STATE),gotoT))
val actionRows=string_to_table(string_to_pairlist_default(T,entry_to_action),actionRows)
val actionRowNumbers = string_to_list actionRowNumbers
val actionT = let val actionRowLookUp=
let val a=Array.fromList(actionRows) in fn i=>Array.sub(a,i) end
in Array.fromList(map actionRowLookUp actionRowNumbers)
end
in LrTable.mkLrTable {actions=actionT,gotos=gotoT,numRules=numrules,
numStates=numstates,initialState=STATE 0}
end
end
local open Header in
type pos = int
type arg = unit
structure MlyValue = 
struct
datatype svalue = VOID | ntVOID of unit ->  unit
 | VAR of unit ->  (int) | NUM of unit ->  (int)
 | PROG of unit ->  (Core.Cmd) | COMMAND of unit ->  (Core.Cmd)
 | EXP of unit ->  (Core.Expr)
end
type svalue = MlyValue.svalue
type result = Core.Cmd
end
structure EC=
struct
open LrTable
infix 5 $$
fun x $$ y = y::x
val is_keyword =
fn (T 8) => true | (T 9) => true | (T 10) => true | (T 15) => true | _ => false
val preferred_change : (term list * term list) list = 
(nil
,nil
 $$ (T 4))::
(nil
,nil
 $$ (T 6))::
nil
val noShift = 
fn (T 0) => true | _ => false
val showTerminal =
fn (T 0) => "EOF"
  | (T 1) => "SEMI"
  | (T 2) => "LPAREN"
  | (T 3) => "NUM"
  | (T 4) => "PLUS"
  | (T 5) => "RPAREN"
  | (T 6) => "TIMES"
  | (T 7) => "ZERO"
  | (T 8) => "LOOP"
  | (T 9) => "IF"
  | (T 10) => "ELSE"
  | (T 11) => "CHOOSE"
  | (T 12) => "OR"
  | (T 13) => "VAR"
  | (T 14) => "ASSIGN"
  | (T 15) => "SKIP"
  | (T 16) => "LBRACE"
  | (T 17) => "RBRACE"
  | _ => "bogus-term"
local open Header in
val errtermvalue=
fn _ => MlyValue.VOID
end
val terms : term list = nil
 $$ (T 17) $$ (T 16) $$ (T 15) $$ (T 14) $$ (T 12) $$ (T 11) $$ (T 10)
 $$ (T 9) $$ (T 8) $$ (T 7) $$ (T 6) $$ (T 5) $$ (T 4) $$ (T 2) $$ (T 
1) $$ (T 0)end
structure Actions =
struct 
exception mlyAction of int
local open Header in
val actions = 
fn (i392,defaultPos,stack,
    (()):arg) =>
case (i392,stack)
of  ( 0, ( ( _, ( MlyValue.COMMAND COMMAND1, COMMAND1left, 
COMMAND1right)) :: rest671)) => let val  result = MlyValue.PROG (fn _
 => let val  COMMAND1 = COMMAND1 ()
 in (COMMAND1)
end)
 in ( LrTable.NT 2, ( result, COMMAND1left, COMMAND1right), rest671)

end
|  ( 1, ( ( _, ( _, SKIP1left, SKIP1right)) :: rest671)) => let val  
result = MlyValue.COMMAND (fn _ => (Core.Skip))
 in ( LrTable.NT 1, ( result, SKIP1left, SKIP1right), rest671)
end
|  ( 2, ( ( _, ( MlyValue.EXP EXP1, _, EXP1right)) :: _ :: ( _, ( 
MlyValue.VAR VAR1, VAR1left, _)) :: rest671)) => let val  result = 
MlyValue.COMMAND (fn _ => let val  (VAR as VAR1) = VAR1 ()
 val  (EXP as EXP1) = EXP1 ()
 in (Core.Asgn(VAR,EXP))
end)
 in ( LrTable.NT 1, ( result, VAR1left, EXP1right), rest671)
end
|  ( 3, ( ( _, ( MlyValue.COMMAND COMMAND2, _, COMMAND2right)) :: _ ::
 ( _, ( MlyValue.COMMAND COMMAND1, COMMAND1left, _)) :: rest671)) =>
 let val  result = MlyValue.COMMAND (fn _ => let val  COMMAND1 = 
COMMAND1 ()
 val  COMMAND2 = COMMAND2 ()
 in (Core.Seq(COMMAND1,COMMAND2))
end)
 in ( LrTable.NT 1, ( result, COMMAND1left, COMMAND2right), rest671)

end
|  ( 4, ( ( _, ( _, _, RPAREN1right)) :: ( _, ( MlyValue.COMMAND 
COMMAND1, _, _)) :: _ :: ( _, ( MlyValue.VAR VAR1, _, _)) :: ( _, ( _,
 LOOP1left, _)) :: rest671)) => let val  result = MlyValue.COMMAND (fn
 _ => let val  (VAR as VAR1) = VAR1 ()
 val  (COMMAND as COMMAND1) = COMMAND1 ()
 in (Core.Loop(VAR, COMMAND))
end)
 in ( LrTable.NT 1, ( result, LOOP1left, RPAREN1right), rest671)
end
|  ( 5, ( ( _, ( _, _, RPAREN2right)) :: ( _, ( MlyValue.COMMAND 
COMMAND2, _, _)) :: _ :: _ :: _ :: ( _, ( MlyValue.COMMAND COMMAND1, _
, _)) :: _ :: ( _, ( _, IF1left, _)) :: rest671)) => let val  result =
 MlyValue.COMMAND (fn _ => let val  COMMAND1 = COMMAND1 ()
 val  COMMAND2 = COMMAND2 ()
 in (Core.Choice(COMMAND1,COMMAND2))
end)
 in ( LrTable.NT 1, ( result, IF1left, RPAREN2right), rest671)
end
|  ( 6, ( ( _, ( _, _, RPAREN2right)) :: ( _, ( MlyValue.COMMAND 
COMMAND2, _, _)) :: _ :: _ :: _ :: ( _, ( MlyValue.COMMAND COMMAND1, _
, _)) :: _ :: ( _, ( _, CHOOSE1left, _)) :: rest671)) => let val  
result = MlyValue.COMMAND (fn _ => let val  COMMAND1 = COMMAND1 ()
 val  COMMAND2 = COMMAND2 ()
 in (Core.Choice(COMMAND1,COMMAND2))
end)
 in ( LrTable.NT 1, ( result, CHOOSE1left, RPAREN2right), rest671)
end
|  ( 7, ( ( _, ( MlyValue.VAR VAR1, VAR1left, VAR1right)) :: rest671))
 => let val  result = MlyValue.EXP (fn _ => let val  (VAR as VAR1) = 
VAR1 ()
 in (Core.Var(VAR))
end)
 in ( LrTable.NT 0, ( result, VAR1left, VAR1right), rest671)
end
|  ( 8, ( ( _, ( MlyValue.EXP EXP2, _, EXP2right)) :: _ :: ( _, ( 
MlyValue.EXP EXP1, EXP1left, _)) :: rest671)) => let val  result = 
MlyValue.EXP (fn _ => let val  EXP1 = EXP1 ()
 val  EXP2 = EXP2 ()
 in (Core.plus(EXP1,EXP2))
end)
 in ( LrTable.NT 0, ( result, EXP1left, EXP2right), rest671)
end
|  ( 9, ( ( _, ( MlyValue.EXP EXP2, _, EXP2right)) :: _ :: ( _, ( 
MlyValue.EXP EXP1, EXP1left, _)) :: rest671)) => let val  result = 
MlyValue.EXP (fn _ => let val  EXP1 = EXP1 ()
 val  EXP2 = EXP2 ()
 in (Core.times(EXP1,EXP2))
end)
 in ( LrTable.NT 0, ( result, EXP1left, EXP2right), rest671)
end
|  ( 10, ( ( _, ( _, ZERO1left, ZERO1right)) :: rest671)) => let val  
result = MlyValue.EXP (fn _ => (Core.Zero))
 in ( LrTable.NT 0, ( result, ZERO1left, ZERO1right), rest671)
end
|  ( 11, ( ( _, ( _, _, RBRACE1right)) :: ( _, ( MlyValue.EXP EXP1, _,
 _)) :: ( _, ( _, LBRACE1left, _)) :: rest671)) => let val  result = 
MlyValue.EXP (fn _ => let val  EXP1 = EXP1 ()
 in (EXP1)
end)
 in ( LrTable.NT 0, ( result, LBRACE1left, RBRACE1right), rest671)
end
| _ => raise (mlyAction i392)
end
val void = MlyValue.VOID
val extract = fn a => (fn MlyValue.PROG x => x
| _ => let exception ParseInternal
	in raise ParseInternal end) a ()
end
end
structure Tokens : BJK_TOKENS =
struct
type svalue = ParserData.svalue
type ('a,'b) token = ('a,'b) Token.token
fun EOF (p1,p2) = Token.TOKEN (ParserData.LrTable.T 0,(
ParserData.MlyValue.VOID,p1,p2))
fun SEMI (p1,p2) = Token.TOKEN (ParserData.LrTable.T 1,(
ParserData.MlyValue.VOID,p1,p2))
fun LPAREN (p1,p2) = Token.TOKEN (ParserData.LrTable.T 2,(
ParserData.MlyValue.VOID,p1,p2))
fun NUM (i,p1,p2) = Token.TOKEN (ParserData.LrTable.T 3,(
ParserData.MlyValue.NUM (fn () => i),p1,p2))
fun PLUS (p1,p2) = Token.TOKEN (ParserData.LrTable.T 4,(
ParserData.MlyValue.VOID,p1,p2))
fun RPAREN (p1,p2) = Token.TOKEN (ParserData.LrTable.T 5,(
ParserData.MlyValue.VOID,p1,p2))
fun TIMES (p1,p2) = Token.TOKEN (ParserData.LrTable.T 6,(
ParserData.MlyValue.VOID,p1,p2))
fun ZERO (p1,p2) = Token.TOKEN (ParserData.LrTable.T 7,(
ParserData.MlyValue.VOID,p1,p2))
fun LOOP (p1,p2) = Token.TOKEN (ParserData.LrTable.T 8,(
ParserData.MlyValue.VOID,p1,p2))
fun IF (p1,p2) = Token.TOKEN (ParserData.LrTable.T 9,(
ParserData.MlyValue.VOID,p1,p2))
fun ELSE (p1,p2) = Token.TOKEN (ParserData.LrTable.T 10,(
ParserData.MlyValue.VOID,p1,p2))
fun CHOOSE (p1,p2) = Token.TOKEN (ParserData.LrTable.T 11,(
ParserData.MlyValue.VOID,p1,p2))
fun OR (p1,p2) = Token.TOKEN (ParserData.LrTable.T 12,(
ParserData.MlyValue.VOID,p1,p2))
fun VAR (i,p1,p2) = Token.TOKEN (ParserData.LrTable.T 13,(
ParserData.MlyValue.VAR (fn () => i),p1,p2))
fun ASSIGN (p1,p2) = Token.TOKEN (ParserData.LrTable.T 14,(
ParserData.MlyValue.VOID,p1,p2))
fun SKIP (p1,p2) = Token.TOKEN (ParserData.LrTable.T 15,(
ParserData.MlyValue.VOID,p1,p2))
fun LBRACE (p1,p2) = Token.TOKEN (ParserData.LrTable.T 16,(
ParserData.MlyValue.VOID,p1,p2))
fun RBRACE (p1,p2) = Token.TOKEN (ParserData.LrTable.T 17,(
ParserData.MlyValue.VOID,p1,p2))
end
end
